<!DOCTYPE html>
<html>
<head>
    <title>Physics Diagram of Induced Electric Field</title>
    <style>
        canvas {
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>

<canvas id="physicsCanvas" width="500" height="500"></canvas>

<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // --- Drawing parameters ---
    const cx = 250;
    const cy = 230; // Center canvas vertically
    const R_px = 150;
    const r_px = 75;
    const pointRadius = 4;
    const crossSize = 10;
    const tickSize = 10;

    // --- Helper Function to draw a cross ---
    function drawCross(x, y, size) {
        ctx.beginPath();
        ctx.moveTo(x - size / 2, y - size / 2);
        ctx.lineTo(x + size / 2, y + size / 2);
        ctx.moveTo(x + size / 2, y - size / 2);
        ctx.lineTo(x - size / 2, y + size / 2);
        ctx.stroke();
    }

    // --- Main Drawing Logic ---
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';

    // 1. Draw the Outer Circle
    ctx.lineWidth = 2;
    ctx.beginPath();
    ctx.arc(cx, cy, R_px, 0, 2 * Math.PI);
    ctx.stroke();

    // 2. Draw the Magnetic Field Crosses
    ctx.lineWidth = 1.5;
    const spacing = 45;
    for (let i = -3; i <= 3; i++) {
        for (let j = -3; j <= 3; j++) {
            const x = cx + i * spacing;
            const y = cy + j * spacing;
            // Exclude the center cross which will be drawn with the 'O' label
            if (i === 0 && j === 0) continue;
            // Check if the cross is inside the circle
            if (Math.sqrt((x-cx)*(x-cx) + (y-cy)*(y-cy)) < R_px - crossSize) {
                drawCross(x, y, crossSize);
            }
        }
    }

    // Reset line width for main features
    ctx.lineWidth = 2;
    ctx.font = '22px serif';

    // 3. Draw Radius R line and label
    ctx.beginPath();
    ctx.moveTo(cx, cy);
    ctx.lineTo(cx + R_px, cy);
    ctx.stroke();
    ctx.textAlign = 'center';
    ctx.textBaseline = 'bottom';
    ctx.fillText('R', cx + R_px * 0.65, cy - 5);

    // 4. Draw points and labels A, C, O
    // Point C
    const c_x = cx;
    const c_y = cy - r_px;
    ctx.beginPath();
    ctx.arc(c_x, c_y, pointRadius, 0, 2 * Math.PI);
    ctx.fill();
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';
    ctx.fillText('C', c_x + 10, c_y);

    // Point A
    const a_x = cx;
    const a_y = cy + r_px;
    ctx.beginPath();
    ctx.arc(a_x, a_y, pointRadius, 0, 2 * Math.PI);
    ctx.fill();
    ctx.fillText('A', a_x + 10, a_y);

    // Point O (Center)
    ctx.lineWidth = 1.5;
    drawCross(cx, cy, 14); // Draw the cross at the center
    ctx.lineWidth = 2;
    ctx.textAlign = 'right';
    ctx.textBaseline = 'middle';
    ctx.fillText('O', cx - 12, cy);


    // 5. Draw vertical line and distance 'r' indicators
    // Vertical line segment OC and OA
    ctx.beginPath();
    ctx.moveTo(c_x, c_y);
    ctx.lineTo(a_x, a_y);
    ctx.stroke();

    // For distance OC
    ctx.beginPath();
    ctx.moveTo(c_x - tickSize / 2, c_y);
    ctx.lineTo(c_x + tickSize / 2, c_y);
    ctx.stroke();
    ctx.beginPath();
    ctx.moveTo(cx - tickSize / 2, cy);
    ctx.lineTo(cx + tickSize / 2, cy);
    ctx.stroke();
    ctx.textAlign = 'left';
    ctx.fillText('r', cx + 15, cy - r_px / 2);

    // For distance OA
    ctx.beginPath();
    ctx.moveTo(a_x - tickSize / 2, a_y);
    ctx.lineTo(a_x + tickSize / 2, a_y);
    ctx.stroke();
    ctx.textAlign = 'right';
    ctx.fillText('r', cx - 15, cy + r_px / 2);

    // 6. Draw label B
    ctx.font = 'italic bold 28px serif';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    ctx.fillText('B', cx - R_px / 2, cy - R_px / 2.5);

    // 7. Draw Caption
    ctx.font = '24px "KaiTi", "STKaiti", "serif"';
    ctx.fillStyle = 'black';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'top';
    ctx.fillText('习题 9-15 图', cx, cy + R_px + 40);

</script>

</body>
</html>